package com.ting.etp.spring.config;

import com.ting.etp.spring.plugin.LocalStoragePlugin;
import com.ting.etp.spring.plugin.StoragePlugin;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@ConditionalOnProperty(prefix = "storage", name = "type", havingValue = "local")
@EnableConfigurationProperties(LocalStorageProperties.class)
public class LocalStorageAutoConfiguration {
    
    @Bean
    @ConditionalOnMissingBean
    public StoragePlugin localStoragePlugin(LocalStorageProperties properties) {
        return new LocalStoragePlugin(properties.getRootPath());
    }
}